package com.ncr.travel.appmgr.service.provider.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.ncr.travel.appmgr.model.ColumnSpecificationJson;
import com.ncr.travel.appmgr.model.RowSpecificationJson;
import com.ncr.travel.appmgr.model.RuleJson;
import com.ncr.travel.appmgr.model.TableDefinitionJson;
import com.ncr.travel.appmgr.model.shared.ColumnSpecification;
import com.ncr.travel.appmgr.model.shared.RowSpecification;
import com.ncr.travel.appmgr.model.shared.Rule;
import com.ncr.travel.appmgr.model.shared.TableDefinition;
import com.ncr.travel.appmgr.service.provider.RulesProvider;

@Component
public class RulesProviderImplImpl implements RulesProvider {

	/*private MockDatabase mockDataBase;

	@Autowired
	public RulesProviderImplImpl(MockDatabase mockDataBase) {
		this.mockDataBase = mockDataBase;
	}*/

	/**
	 * @see com.com.ncr.travel.appmgr.service.provider.com.ncr.travel.appmgr.service.provider.RulesProvider#getRulesByScreenName(java.lang.String)
	 */
	@Override
	public Rule getRulesByScreenName(String screenName) {

		Rule rules = null;

		if (screenName.equals("AddMileagePlan")) {
			rules = new RuleJson();
			rules.setRuleName("Mileage Plan");
			rules.setScreenName(screenName);
			rules.setDescription("Mileage plan rule.");
			TableDefinitionJson tableDefinations = new TableDefinitionJson();
			RowSpecificationJson rowSpecifications = new RowSpecificationJson();

			rowSpecifications.setRowName("Mileage Plan Program");
			rowSpecifications.setRowValue("Alaska Airline");

			List<ColumnSpecification> colList = new ArrayList<ColumnSpecification>();
			addColumnValues("Mileage Plan Code", "A5", colList);
			addColumnValues("Allowed For Mileage Credit", "true", colList);
			addColumnValues("Show Airline Name", "false", colList);
			RowSpecificationJson rowSpecifications2 = new RowSpecificationJson();

			rowSpecifications2.setRowName("Mileage Plan Program");
			rowSpecifications2.setRowValue("Delta Airline");

			List<ColumnSpecification> colList2 = new ArrayList<ColumnSpecification>();
			addColumnValues("Mileage Plan Code", "A5", colList2);
			addColumnValues("Allowed For Mileage Credit", "true", colList2);
			addColumnValues("Show Airline Name", "false", colList2);

			rowSpecifications.setColSpecification(colList);
			rowSpecifications2.setColSpecification(colList2);
			List<RowSpecification> listRows = new ArrayList<RowSpecification>();
			listRows.add(rowSpecifications);
			listRows.add(rowSpecifications2);

			tableDefinations.setRowSpecification(listRows);
			tableDefinations.setRowCount(2);
			tableDefinations.setColumnCount(3);
			List<TableDefinition> listTables = new ArrayList<TableDefinition>();
			listTables.add(tableDefinations);
			rules.setTableDefinition(listTables);

			return rules;

		} else if (screenName.equals("SpecialServiceRequestsCode")) {
			rules = new RuleJson();
			rules.setRuleName("Special Service Requests (SSR) Code");
			rules.setScreenName(screenName);
			rules.setDescription("Special Service Requests (SSR) Code.");
			TableDefinitionJson tableDefinations = new TableDefinitionJson();

			RowSpecificationJson rowSpecifications = new RowSpecificationJson();

			List<ColumnSpecification> colList = new ArrayList<ColumnSpecification>();
			addColumnValues("SSR", "PETC", colList);
			RowSpecificationJson rowSpecifications2 = new RowSpecificationJson();

			List<ColumnSpecification> colList2 = new ArrayList<ColumnSpecification>();
			addColumnValues("SSR", "UMNR", colList2);
			RowSpecificationJson rowSpecifications3 = new RowSpecificationJson();

			List<ColumnSpecification> colList3 = new ArrayList<ColumnSpecification>();
			addColumnValues("SSR", "BLND", colList3);
			rowSpecifications.setColSpecification(colList);
			rowSpecifications2.setColSpecification(colList2);
			rowSpecifications3.setColSpecification(colList3);
			List<RowSpecification> listRows = new ArrayList<RowSpecification>();
			listRows.add(rowSpecifications);
			listRows.add(rowSpecifications2);
			listRows.add(rowSpecifications3);
			tableDefinations.setRowSpecification(listRows);
			tableDefinations.setRowCount(3);
			tableDefinations.setColumnCount(1);
			List<TableDefinition> listTables = new ArrayList<TableDefinition>();
			listTables.add(tableDefinations);
			rules.setTableDefinition(listTables);

			return rules;
		} else if (screenName.equals("Offer")) {
			rules = new RuleJson();
			rules.setRuleName("Offer");
			rules.setScreenName(screenName);
			TableDefinitionJson tableDefinations = new TableDefinitionJson();

			RowSpecificationJson rowSpecifications = new RowSpecificationJson();

			rowSpecifications.setRowName("Domestic");
			rowSpecifications.setRowValue("First Class");

			List<ColumnSpecification> colList = new ArrayList<ColumnSpecification>();
			addColumnValues("Exit Row", "$10", colList);
			addColumnValues("Bulkhead", "$20", colList);
			addColumnValues("Premium Cabin", "$60", colList);
			RowSpecificationJson rowSpecifications2 = new RowSpecificationJson();

			rowSpecifications2.setRowValue("Busssiness Class");
			rowSpecifications2.setRowName("Domestic");
			List<ColumnSpecification> colList2 = new ArrayList<ColumnSpecification>();
			addColumnValues("Exit Row", "$20", colList2);
			addColumnValues("Bulkhead", "$40", colList2);
			addColumnValues("Premium Cabin", "$90", colList2);
			rowSpecifications.setColSpecification(colList);
			rowSpecifications2.setColSpecification(colList2);
			List<RowSpecification> listRows = new ArrayList<RowSpecification>();
			listRows.add(rowSpecifications);
			listRows.add(rowSpecifications2);
			tableDefinations.setRowSpecification(listRows);
			tableDefinations.setRowCount(2);
			tableDefinations.setColumnCount(3);
			TableDefinitionJson tableDefinations2 = new TableDefinitionJson();

			RowSpecificationJson rowSpecifications21 = new RowSpecificationJson();

			rowSpecifications21.setRowValue("First Class");
			rowSpecifications21.setRowName("International");

			List<ColumnSpecification> colList21 = new ArrayList<ColumnSpecification>();
			addColumnValues("Exit Row", "$10", colList21);
			addColumnValues("Bulkhead", "$20", colList21);
			addColumnValues("Premium Cabin", "$60", colList21);
			RowSpecificationJson rowSpecifications221 = new RowSpecificationJson();

			rowSpecifications221.setRowValue("Busssiness Class");
			rowSpecifications221.setRowName("International");

			List<ColumnSpecification> colList221 = new ArrayList<ColumnSpecification>();
			addColumnValues("Exit Row", "$20", colList221);
			addColumnValues("Bulkhead", "$40", colList221);
			addColumnValues("Premium Cabin", "$90", colList221);
			rowSpecifications21.setColSpecification(colList21);
			rowSpecifications221.setColSpecification(colList221);
			List<RowSpecification> listRows21 = new ArrayList<RowSpecification>();
			listRows21.add(rowSpecifications21);
			listRows21.add(rowSpecifications221);
			tableDefinations2.setRowSpecification(listRows21);
			tableDefinations2.setRowCount(2);
			tableDefinations2.setColumnCount(3);
			List<TableDefinition> listTables21 = new ArrayList<TableDefinition>();
			listTables21.add(tableDefinations);
			listTables21.add(tableDefinations2);
			rules.setTableDefinition(listTables21);

			return rules;
		}
		return rules;

	}

	private void addColumnValues(String columnName, Object columnValue, List<ColumnSpecification> listColSpec) {
		ColumnSpecificationJson colSpecification = new ColumnSpecificationJson();
		colSpecification.setColumnName(columnName);
		colSpecification.setColumnValue(columnValue.toString());
		listColSpec.add(colSpecification);
	}

}
